<template>
    <hsa-adaptive-container>
        <hsa-adaptive-pane>
            <el-input v-model="inputCookie" type="textarea" :rows="5" placeholder="填写 Cookie" />
        </hsa-adaptive-pane>
        <hsa-adaptive-pane>
            <el-button type="primary" size="large" style="width: 100%;" @click="saveCookie">保存</el-button>
        </hsa-adaptive-pane>
    </hsa-adaptive-container>
</template>

<script setup lang="ts">
    import { ref } from 'vue'
    import { ElMessage } from 'element-plus'

    const inputCookie = ref('')

    const saveCookie = () => {
        if (!inputCookie.value) {
            ElMessage.warning('请输入 Cookie')
            return
        }

        try {
            // 分割多个cookie并逐个设置
            const cookies = inputCookie.value.split(';')
            cookies.forEach(cookie => {
                if (cookie.trim()) {
                    document.cookie = cookie.trim()
                }
            })

            ElMessage.success('Cookie 写入成功')
        } catch (error) {
            ElMessage.error('Cookie 写入失败')
            console.error('Save cookie error:', error)
        }
    }
</script>

<style lang="scss" scoped></style>